package com.gec.system.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gec.model.system.Member;
import com.gec.system.service.MemberService;
import com.gec.system.util.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "会员管理系统")
@RestController
@RequestMapping("/admin/movie/member") //隔日请求加上父路径
public class MemberController {
    @Autowired
    private MemberService memberService;
    // 分页
    @ApiOperation("分页")
    @GetMapping("/{page}/{limit}")
    public Result selectMemberPageByVo(@PathVariable Long page,
                                     @PathVariable Long limit)
    {
        IPage<Member> iPage = new Page<>(page,limit);

        iPage =   this.memberService.selectPage(iPage);

        return Result.ok(iPage);
    }
    // 添加影视
    @ApiOperation("添加")
    @PostMapping("/addMember")
    public Result addMember(@RequestBody Member member) {
        boolean b = this.memberService.save(member);
        if (b)
        {
            return Result.ok();
        }
        else
        {
            return Result.fail();
        }
    }
    // 根据id 去获取一个用户
    @ApiOperation("根据id 去获取一个影视")
    @GetMapping("/findMemberById/{id}")
    public Result findMemberById(@PathVariable Long id)
    {
        Member member = this.memberService.getById(id);
        return Result.ok(member);
    }
    @ApiOperation("修改实现")
    @PostMapping("/updateMember")
    public Result updateMember(@RequestBody Member member)
    {
        boolean b = this.memberService.updateById(member);
        if (b)
        {
            return Result.ok();
        }
        else
        {
            return Result.fail();
        }
    }
    // 删除
    @ApiOperation("删除")
    @DeleteMapping("/removeMemberById/{id}")
    public Result removeBatchMemberByIds(@PathVariable Long id)
    {
        boolean b = this.memberService.removeById(id);
        if (b)
        {
            return Result.ok();
        }
        else
        {
            return Result.fail();
        }
    }
    // 批量删除
    @ApiOperation("批量删除")
    @DeleteMapping("/batchRemove")
    public Result batchRemove(@RequestBody List<Long> ids)
    {
        boolean isSuccess = this.memberService.removeByIds(ids);
        if (isSuccess)
        {
            return Result.ok();
        }
        else
        {
            return Result.fail();
        }
    }
}
